<template>
	
 	<div class="layui-layout layui-layout-admin" >
 	  <div class="adminnav1">	
        <Pagetop></Pagetop>
      </div>
      <div class="adminnav2">	
       	<Secondnav urlname="user"></Secondnav>
      </div>
      
      <!-- 主体内容 -->
      <div class="layui-body kedou-admin" id="LAY_app_body app">
	    <div class="layadmin-tabsbody-item layui-show">
	    	<div class="pagelist">
	    		<div class="layui-card-body">
		      		<fieldset class="layui-elem-field layui-field-title">
					  <legend>商家会员</legend>
					</fieldset>
		      	</div>
	    		<div class="pagetop">
	    			<Search :seadate="searchArr"></Search>			    	
		        </div>
		        <div class="layui-card-body">
		        	<div class="buttop">
		        		<button type="button" class="layui-btn" @click="levelset">会员等级设置</button>
					    <button type="button" class="layui-btn  layui-btn-normal" @click="addData">添加会员</button>
					</div>
			        <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex" :fbtn="btn"></Tables>      			     
		        </div>		      
	        </div>
	    </div>
	  </div>  
	     
	</div>
</template>
<script>	
	import Pagetop from '../../common/pagetop.vue'
	import Secondnav from '../../common/secondnav.vue'
	import Tables from '../../common/tables.vue'
	import Search from '../../common/search.vue'
	export default {
	  name: 'memberlist',
	  components: {Pagetop,Secondnav,Tables,Search},	  
	  data () {
	    return {
	        pdate:[], //表头  	
	    	res:"", //内容
	    	totalRows:"",//总数量
	    	curindex:1, //页数
	    	btn:[],//按钮
	    	searchArr:[],//搜索
	    	isShow:false, 
	    	seapram:'',	    	
	    	shopId:localStorage.getItem("shopId"),
	    }
	  },
	  mounted(){ 	
	  	this.getdate();
     	this.getsearch();
	  },
	  methods: {	 	  
		getdate:function(){     	
    	var _this=this;    	    	
    	var url="/shop/papi/v1.9/members"
    	if(_this.seapram){
    		var dates={
	    		 size:pageSize,
	    		 page:_this.curindex,
	    		 'shopId.equals':_this.shopId,	
		         sort:'createAt,DESC',
		         //'status.equals':'ENABLE'
	    	}
    		var res=_this.seapram;
    		for(var i=0;i<res.length;i++){
    			dates[res[i].key+'.equals']=res[i].val;
    		}
    		
    	}else{
	    	var dates={
	    		 size:pageSize,
	    		 page:_this.curindex,
	    		 'shopId.equals':_this.shopId,	
		         sort:'createAt,DESC',
		         //'status.equals':'ENABLE'
	    	}
        }    		    	
        	//alert(url+"//"+JSON.stringify(dates))
    	ajaxRequest(url,'GET','json',dates,function(ret,err){
    		//alert(url+"//"+JSON.stringify(ret))
	  		var arr=[];  		
		  	arr[0]=[ 
		       {field: 'id', title: 'ID',}		      		     	       
		      ,{field: 'mobile', title: '会员手机',}
		      ,{field: 'level', title: '会员等级',templet:function(d){
		      	 if(d.level){return d.level.name		      	 	
//			         if(d.level.name=='ZERO')return '非会员'
//			         else if(d.level.name=='ONE') return '1级'
//			         else if(d.level.name=='TWO')return '2级'
//			         else if(d.level.name=='THREE')return '3级'
//			         else if(d.level.name=='FOUR')return '4级'
//			         else if(d.level.name=='FIVE')return '5级'
//			         else if(d.level.name=='SIX')return '6级'
//			         else if(d.level.name=='SEVEN')return '7级'
//			         else if(d.level.name=='EIGHT')return '8级'
//			         else if(d.level.name=='NINE')return '9级'
//			         else if(d.level.name=='TEN')return '10级'
//			         else if(d.level.name=='ELEVEN')return '11级'
//			         else if(d.level.name=='TWELVE')return '12级'
//			         else if(d.level.name=='THIRTEEN')return '13级'
//			         else if(d.level.name=='FOURTEEN')return '14级'
//			         else if(d.level.name=='FIFTEEN')return '15级'
		        }
		      }}
		      ,{field: 'createAt', title: '创建时间',templet:function(d){return FormatDate(d.createAt,2)}}
		      ,{field: 'status', title: '状态',templet:function(d){
		      	  if(d.status=='DISABLE')return '禁用'
			      else if(d.status=='ENABLE') return '启用'
			      else return '删除'
		      }}		       
		      ,{field: 'right',title: '操作', width:'120', fixed:'right',templet:function(d){ 
		         var str='<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>';
		         return str;
		      }}
		    ];		   
		  	_this.pdate=arr;		  	
		  	_this.res=ret.data.list;  		  
		  	_this.totalRows=ret.data.totalRows;
		  	_this.curindex=ret.data.pageNumber+1;		  	
	    })	
    },     
    getsearch:function(){
    	var arr=[
    		{field: 'mobile', title: '手机号',type: 'input'}    	   
    	];
    	this.searchArr=arr;   	
    },
    page:function(index,obj){
    	//alert(JSON,stringify(obj))
    	this.curindex=index;
    	this.getdate();
    	
    }, 
    sousuo:function(pram){
    	//alert(JSON.stringify(pram))
    	this.seapram=pram;
    	this.res='';
    	this.totalRows='';
    	this.curindex=1;
    	this.getdate();
    },
    levelset:function(){
    	this.$router.push({name:'levelist'})
    },
    addData:function(){   	
    	var _this = this;
		layer.open({
	      type: 2
	      ,title: '新增会员'
	      ,content:baseurl+'/memberadd'
	      ,area:['70%', '70%']
	    });
    },
    editInfo:function(data){
    	var _this = this;
	  	layer.open({
	      type: 2
	      ,title: '编辑会员'
	      ,content:baseurl+'/memberadd'
	      ,area: ['70%', '70%']
	      ,success : function(layero, index){
	        var iframeWin = window[layero.find('iframe')[0]['name']];
	        iframeWin.getdates(data);
	      },
	    });
    },
	screens:function(){
		return screen();
	},	
  },
  updated:function(){
  	this.isShow = true;
	layui.use('form', function(){
	  var form = layui.form;
	  form.render();	 
	});
  },
}
</script>
<style scoped>
/**/
</style>
